home *** CD-ROM | disk | FTP | other *** search
- Path: wkaufman.us.oracle.com!wkaufman
- From: wkaufman@wkaufman.us.oracle.com (William Kaufman)
- Newsgroups: comp.lang.c
- Subject: Re: Q: "Overlapping Objects"
- Date: 14 Apr 1996 23:10:48 GMT
- Organization: Oracle Corporation, Redwood Shores CA
- Message-ID: <4ks0lo$b1n@inet-nntp-gw-1.us.oracle.com>
- References: <31714280.201A@micromedia.on.ca>
- NNTP-Posting-Host: wkaufman.us.oracle.com
-
- In article <31714280.201A@micromedia.on.ca> Richard Steadman <rsteadma@micromedia.on.ca> writes:
- ] Hello.
- ]
- ] I have a question which is quite simple, but I can't seem to find
- ] the right answer anywhere.
- ]
- ] I'm trying to figure out when it is necessary to use the memmove()
- ] function when copying strings. K&R and the man page says to use it
- ] when the "objects overlap". But I can't find a formal definition
- ] for this phrase (it's not in the FAQ either -- I checked!).
-
- If you've got two pointers into the same piece of memory, they
- overlap if either pointer is in the middle of the other's region (i.e.,
- between the other pointer and that pointer plus the size you're
- copying).
-
- ] Here's the scenario: I have a string, and want to copy the tail of
- ] it to an earlier part of the string. The two pieces are *not*
- ] overlappng when the function is called, but they may be when the
- ] copy is finished.
- ]
- ] Given this, it safe to use strcat() instead of memmove()?
-
- I'm not sure I understand--they either overlap or they don't, and
- asking _at what time_ fixed chunks of memory overlap doesn't make sense
- to me. But I think your answer is "No".
-
- -- Bill K.
-
- Bill Kaufman | "I mean ... it's not even been a two-and-two-make-
- wkaufman@us.oracle.com | five sort of day, it's more like a two-and-two-
- | make ... *fish* ..." -- "Cages", Dave McKean
-